Debugging on mips targets

Contents|Index|Previous|Next
Debugging on MIPS targets

The following documentation discusses debugging with MIPS.

- Linking MIPS with the GOFAST library
- Full compatibility with the GOFAST library for MIPS

GDB needs to know the following things to talk to your MIPS target.

- Specifications for what serial device connects your host to your MIPS board (the first serial device available on your host is the default).
- Specifications for what speed to use over the serial device.

Use one of the following GDB commands to specify the connection to your target board.

- target mips port
To run a program on the board, start up GDB with the name of your program as the argument.
To connect to the board, use the command, target mips port, where port is the name of the serial port connected to the board. If the program has not already been downloaded to the board, you may use the load command to download it.
You can then use all the usual GDB commands.
For example, the following sequence connects to the target board through a serial port, and loads and runs a program called prog through the debugger.

    host$ mips-elf-gdb prog
    GDB is free software and...
    (gdb) target mips /dev/ttyb
    ...
    (gdb) load
    ...
    (gdb) run

- target mips hostname: portnumber
You can specify a TCP/IP connection instead of a serial port, using the syntax hostname: portnumber (assuming your board is connected so that this makes sense; for instance, to a serial line managed by a terminal concentrator).
GDB also supports the special command, set mipsfpu off, for targets.
If your target board does not support the MIPS floating point coprocessor, you should use the command, set mipsfpu off (you may wish to put this in your .gdbinit file). This tells GDB how to find the return value of functions which return floating point values. It also allows GDB to avoid saving the floating point registers when calling functions on the board.
If you neglect to use the command, set mipsfpu off, some calls will fail, such as print strlen("abc").
- set remotedebug n
You can see some debugging information about communications with the board by setting the remotedebug variable. If you set it to 1 using set remotedebug 1, every packet will be displayed. If you set it to 2, every character will be displayed. You can check the current value at any time with the command show remotedebug.

Linking MIPS with the GOFAST library

The GOFAST library is available with two interfaces; gcc -msoft-float output places all arguments in registers, which (for subroutines using double arguments) is compatible with the interface identified as “Interface 1: all arguments in registers” in the GOFAST documentation. For full compatibility with all GOFAST subroutines, you need to make a slight modification to some of the subroutines in the GOFAST library.

If you purchase and install the GOFAST library, you can link your code to that library in a number of different ways, depending on where and how you install the library. To focus on the issue of linking, the following examples assume you’ve already built object modules with appropriate options (including -msoft-float).

This is the simplest case; it assumes that you’ve installed the GOFAST library as the file, fp.a, in the same directory where you do development, as shown in the GOFAST documentation.

    mips-idt-ecoff-gcc -o prog prog.o...-lc fp.a

In a shared development environment, the following example may be more realistic; it assumes you’ve installed the GOFAST library as ‘uss-dir/libgofast.a’, where ‘ussdir’ is any convenient directory on your development system.

    mips-idt-ecoff-gcc -o program program.o... \
                                               -lc -Lussdir -lgofast

Finally, you can eliminate the need for a -L option with a little more setup, using an environment variable like the following example (the example assumes you use a command shell compatible with the Bourne shell):

    LIBRARY_PATH= ussdir; export LIBRARY_PATH
    mips-idt-ecoff-gcc -o program program.o...-lc -lgofast

As for the previous example, the GOFAST library is installed in the directory, uss-dir/libgofast.a. The environment variable, LIBRARY_PATH, instructs GCC to look for the library in ussdir. (The syntax shown here for setting the environment variable is the Unix Bourne Shell, /bin/sh, syntax; adjust as needed for your system.)

Notice that all the variations on linking with the GOFAST library explicitly include -lc before the GOFAST library. -lc is the standard C subroutine library; normally, you don’t have to specify this subroutine, since linking with the GOFAST library is automatic.

When you link with an alternate software floating-point library, however, the order of linking is important. In this situation, specify ‘-lc’ to the left of the GOFAST library, to ensure that standard library subroutines also use the GOFAST floating-point code.

Full compatibility with the GOFAST library for MIPS

The GCC calling convention for functions whose first and second arguments have type float is not completely compatible with the definitions of those functions in the GOFAST library, as shipped. The following functions are affected.

        fpcmp        fpadd        fpsub
        fpmul        fpdiv        fpfmod
        fpacos       fpasin       fpatan
        fpatan2      fppow

Since the GOFAST library is normally shipped with source, you can make these functions compatible with the gcc convention by adding the following instruction to the beginning of each affected function, then rebuilding the library.

    move $5,$6

Top|Contents|Index|Previous|Next